package com.youshang520i;

import org.springframework.web.WebApplicationInitializer;
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
import org.springframework.web.servlet.DispatcherServlet;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.ServletRegistration;

/**
 * @author youshang
 */
public class MyMain implements WebApplicationInitializer {//implements WebApplicationInitializer
//    public static void main(String[] args) {
//        AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(App.class);
////        UsageTracked person = (UsageTracked) ctx.getBean("myServiceImpl");
////        person.incrementUseCount();
//
////        MyService service = (MyService)ctx.getBean("myServiceImpl");
////        service.doSth1();
////        Animal animal = (Animal)person;
////        animal.eat();
//
//    }

    @Override
    public void onStartup(ServletContext servletContext) throws ServletException {
        // Load Spring web application configuration
        AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext();
        context.register(App.class);
//        context.scan("com.youshang520i");
        context.refresh();
        // Create and register the DispatcherServlet
        DispatcherServlet servlet = new DispatcherServlet(context);
        ServletRegistration.Dynamic registration = servletContext.addServlet("app", servlet);
        registration.setLoadOnStartup(1);
        registration.addMapping("/*");
    }
}
